//
//  WBN_FM_MainTableViewCell.m
//  GoodManNews
//
//  Created by 王博男 on 16/1/11.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "WBN_FM_MainTableViewCell.h"
#import "Masonry.h"
#import "WBN_FM_MainCollectionViewCell.h"

@interface WBN_FM_MainTableViewCell () <UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, retain) UIImageView *leftImageV;
@property (nonatomic, retain) UILabel *moreL;
@property (nonatomic, retain) UIImageView *rightImageV;
@property (nonatomic, retain) UILabel *lineL;
@property (nonatomic, retain) UICollectionView *collectionV;

@end

@implementation WBN_FM_MainTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createView];
    }
    return self;
}

- (void)layoutSubviews
{
    [self.leftImageV mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.contentView).offset(10);
        make.left.equalTo(self.contentView).offset(10);
        make.height.equalTo(@20);
        make.width.equalTo(@5);
        
    }];
    
    
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.contentView).offset(10);
        make.left.equalTo(self.leftImageV.mas_right).with.offset(5);
        make.height.equalTo(self.leftImageV.mas_height);
        make.width.equalTo(@80);
        
    }];
    
    
    [self.rightImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.contentView).offset(10);
        make.right.equalTo(self.contentView).offset(-10);
        make.height.equalTo(@20);
        make.width.equalTo(@15);
        
    }];
    
    
    [self.moreL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.contentView).offset(10);
        make.right.equalTo(self.rightImageV.mas_left).with.offset(-5);
        make.height.equalTo(self.rightImageV.mas_height);
        make.width.equalTo(@30);
        
    }];
    
    
    [self.lineL mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.label.mas_bottom).with.offset(10);
        make.height.equalTo(@1);
        make.width.equalTo(self.contentView);
        
    }];
    
    
    [self.collectionV mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.lineL.mas_bottom).with.offset(10);
        make.bottom.equalTo(self.contentView).offset(20);
        make.width.equalTo(self.contentView);
        
    }];
    
}

- (void)createView
{
    self.leftImageV = [UIImageView new];
    self.leftImageV.image = [UIImage imageNamed:@"list_FM_redBar@3x"];
    [self.contentView addSubview:self.leftImageV];
    
    
    self.label = [UILabel new];
    self.label.text = @"凤凰独家";
    self.label.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.label];
    
    
    self.moreL = [UILabel new];
    self.moreL.text = @"更多";
    self.moreL.font = [UIFont systemFontOfSize:14];
    self.moreL.textColor = [UIColor lightGrayColor];
    self.moreL.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.moreL];
    
    
    self.rightImageV = [UIImageView new];
    self.rightImageV.image = [UIImage imageNamed:@"list_FM_more@3x"];
    [self.contentView addSubview:self.rightImageV];
    
    
    self.lineL = [UILabel new];
    self.lineL.backgroundColor = [UIColor lightGrayColor];
    [self.contentView addSubview:self.lineL];
    
    
    UICollectionViewFlowLayout *flowL = [UICollectionViewFlowLayout new];
    flowL.itemSize = CGSizeMake(([[UIScreen mainScreen] bounds].size.width - 30) / 3.0, 210);
    flowL.sectionInset = UIEdgeInsetsMake(0, 5, 0, 5);
    self.collectionV = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowL];
    self.collectionV.backgroundColor = [UIColor clearColor];
    self.collectionV.delegate = self;
    self.collectionV.dataSource = self;
    self.collectionV.scrollEnabled = NO;
    [self.contentView addSubview:self.collectionV];
    
    [self.collectionV registerClass:[WBN_FM_MainCollectionViewCell class] forCellWithReuseIdentifier:@"cellStr"];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 3;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    WBN_FM_MainCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellStr" forIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor colorWithRed:arc4random() % 255 / 255.0 green:arc4random() % 255 / 255.0  blue:arc4random() % 255 / 255.0  alpha:1];
    
    return cell;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
